const fs = require('fs')
const path = require('path')

const extnameList = ['middleware.js','controller.js','service.js']
function createPage(url,fileName){
  for (const file of extnameList) {
    if(!fs.existsSync(path.resolve(url,`${fileName}.${file}`))){
     fs.writeFile(path.resolve(url,`${fileName}.${file}`),'',() => {
      console.log(path.resolve(url,`${fileName}.${file}`),'文件创建成功');
     })
    }else {
      console.log(path.resolve(url,`${fileName}.${file}`),'文件已存在');
    }
  }
}

/**
 * 使用实例
 * 
  const {createPage} = require("@common/utils")
  createPage(__dirname,'index')
 * 
 * **/ 


module.exports = {
  createPage
}